# Maintainer: kpcyrd <kpcyrd[at]archlinux[dot]org>

pkgname=vultr-cli
pkgver=2.20.0
pkgrel=1
pkgdesc='Official command line tool for Vultr services'
url='https://github.com/vultr/vultr-cli'
arch=('loong64' 'x86_64')
license=('Apache')
makedepends=('go')
source=(https://github.com/vultr/${pkgname}/archive/v${pkgver}/${pkgname}-${pkgver}.tar.gz)
sha512sums=('cf6f7686a9629bd6aa95568b9f4ad9757ed4ca86a6f89736bfd032964f9067d13ebdd0f83df16ea41569b670c2f6b70950bf41ddc80d5c06654d833a4368641b')
b2sums=('54bc9ff1c4e91f57bd4e38998bc1a00796f5e3d49aa9127d97b9af47c35e731340c71b465fdad5f7f49f7705f3887f6b8bc4facac4c177b6734bbdeb32ae3932')

build() {
  cd ${pkgname}-${pkgver}
  go build \
    -trimpath \
    -buildmode=pie \
    -mod=readonly \
    -modcacherw \
    -ldflags "-linkmode external -extldflags \"${LDFLAGS}\"" \
    .
}

check() {
  cd ${pkgname}-${pkgver}
  ./vultr-cli --help
}

package() {
  cd ${pkgname}-${pkgver}
  install -Dm 755 vultr-cli -t "${pkgdir}/usr/bin"

  install -d "${pkgdir}/usr/share/bash-completion/completions" \
             "${pkgdir}/usr/share/zsh/site-functions" \
             "${pkgdir}/usr/share/fish/vendor_completions.d"

  # workaround, see https://github.com/vultr/vultr-cli/issues/92#issuecomment-877722219
  export VULTR_API_KEY=x
  ./vultr-cli completion bash > "${pkgdir}/usr/share/bash-completion/completions/vultr-cli"
  ./vultr-cli completion zsh > "${pkgdir}/usr/share/zsh/site-functions/_vultr-cli"
  ./vultr-cli completion fish > "${pkgdir}/usr/share/fish/vendor_completions.d/vultr-cli.fish"
}

# vim: ts=2 sw=2 et:
